package com.nineclock.attendance.utils;

import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.util.CollectionUtils;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.style.column.AbstractColumnWidthStyleStrategy;
import org.apache.poi.ss.usermodel.Cell;

import java.util.List;

public class CustomHandler extends AbstractColumnWidthStyleStrategy {

    private static final int MAX_COLUMN_WIDTH = 4500;

    public CustomHandler() {
    }

    @Override
    protected void setColumnWidth(WriteSheetHolder writeSheetHolder, List<CellData> list, Cell cell, Head head, Integer integer, Boolean aBoolean) {
        boolean needSetWidth = aBoolean || !CollectionUtils.isEmpty(list);
        if (needSetWidth) {
            // 所有是head的cell设置固定的宽度 MAX_COLUMN_WIDTH
            writeSheetHolder.getSheet().setColumnWidth(cell.getColumnIndex(), MAX_COLUMN_WIDTH);
            // 设置默认行高
            // writeSheetHolder.getCachedSheet().setDefaultRowHeightInPoints();
        }
    }
}
